<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->

    <style type="text/css">
        body, html {
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }

        #l-map {
            height: 300px;
            width: 100%;
        }

        #r-result {
            width: 100%;
            font-size: 14px;
            line-height: 20px;
        }
    </style>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=j385oopt9piMnWcoCmUTzCiZGTmPyDbC"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 110%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>检查组管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>检查组管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-button @click="tomap()" class="dalfBut">分布图</el-button>
                <el-button type="primary" @click="todetail()" class="butT">详情页面</el-button>
            </div>
            <hr/>
            <div class="filter-container">
                <el-input placeholder="请输入地址" onkeyup="vue.findMatchPage()" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="findMatchPage()" class="dalfBut">查询</el-button>
                <el-button class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="name" label="公司地址" align="center"></el-table-column>
                <el-table-column prop="lng" label="经度" align="center"></el-table-column>
                <el-table-column prop="lat" label="纬度" align="center"></el-table-column>

                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <div class="add-form">
                <el-dialog title="新增地址" :visible.sync="dialogFormVisible">
                    <iframe id="iframe" src="addmap.html" width="100%" height="400px" frameborder="0"></iframe>
                </el-dialog>
            </div>
        </div>
    </div>

</div>


</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script type="text/javascript">
    // 百度地图API功能
    function G(id) {
        return document.getElementById(id);
    }

    var map = new BMap.Map("l-map");
    map.centerAndZoom("北京", 12);                   // 初始化地图,设置城市和地图级别。

    var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
        {
            "input": "suggestId"
            , "location": map
        });

    ac.addEventListener("onhighlight", function (e) {  //鼠标放在下拉列表上的事件
        var str = "";
        var _value = e.fromitem.value;
        var value = "";
        if (e.fromitem.index > -1) {
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

        value = "";
        if (e.toitem.index > -1) {
            _value = e.toitem.value;
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
        G("searchResultPanel").innerHTML = str;
    });

    var myValue;
    ac.addEventListener("onconfirm", function (e) {    //鼠标点击下拉列表后的事件
        var _value = e.item.value;
        myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
        G("searchResultPanel").innerHTML = "onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;

        setPlace();
    });

    function setPlace() {
        map.clearOverlays();    //清除地图上所有覆盖物
        function myFun() {
            var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
            map.centerAndZoom(pp, 18);
            map.addOverlay(new BMap.Marker(pp));    //添加标注
        }

        var local = new BMap.LocalSearch(map, { //智能搜索
            onSearchComplete: myFun
        });
        local.search(myValue);
    }
</script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            rules: {//校验规则
                code: [{required: true, message: '项目编码为必填项', trigger: 'blur'}],
                name: [{required: true, message: '项目名称为必填项', trigger: 'blur'}]
            }
        },
        mounted: function () {
            this.$nextTick(function () {
                // 初始化
            })
        },

        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            //VUE对象初始化完成后调用分页查询方法,完成分页查询
            this.findPage();

        },
        methods: {
            //添加
            handleAdd() {
                //进行表单校验
                this.$refs['dataAddForm'].validate((valid) => {
                    if (valid) {  //校验通过发送ajax请求,将数据提交到后台
                        console.log(this.formData);
                        axios.post("/checkitem/add.do", this.formData).then((res) => {
                            //关闭添加的窗口(不管执行成功还是失败)
                            this.dialogFormVisible = false;
                            if (res.data.flag) {
                                //添加成功重新调用分页查询
                                this.findPage();
                                //然后弹出提示信息
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                            } else {//失败的
                                //弹出提示信息
                                this.$message.error(res.data.message);
                            }
                        });
                    } else {  //校验不通过
                        this.$message.error("输入有误,");
                        return false;
                    }
                });
            },

            findMatchPage() {
                this.pagination.currentPage = 1;
                this.findPages();
            },

            //分页查询
            findPage() {
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.post("/address/findAll.do", param).then((res) => {
                    //解析Controller相应的数据
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                });
            },
            findPages() {
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.post("/address/findByString.do", param).then((res) => {
                    //解析Controller相应的数据

                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};  //重置数据
            },
            // 弹出添加窗口
            handleCreate() {
                //弹出新增窗口
                this.dialogFormVisible = true;
                this.resetForm();
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                //重新调用findPage方法
                this.findPage();
            },
            tomap() {
                window.location.href = "map.html";

            },
            todetail() {
                window.location.href = "detail.html";
            },
            addsuccess() {
                this.dialogFormVisible = false;
                this.findPage();
                this.$message({
                    type: 'success',
                    message: '添加成功'
                });
            },

            // 删除
            handleDelete(row) {
                this.$confirm("确定删除当前数据?", "提示", {
                    type: 'warning'
                }).then(() => {
                    //alert('确定')
                    //发送ajax请求,将ID提交
                    axios.get("/address/delete.do?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            //成功就提示信息
                            this.$message.success(res.data.message);
                            /*
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                            */
                            this.findPage();  //重新分页查询
                        } else {
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    })
                }).catch(() => {
                    //alert('取消')
                    this.$message({
                        type: 'success',
                        message: '已取消操作'
                    });
                });

            }

        }
    })
</script>
